import pymysql

conn = pymysql.Connect(host='localhost', port=3306, user='root', password='root',
                       database='books', charset='utf8', autocommit=False)

cursor = conn.cursor()

select_sql = "select id, title, pub_date from t_book"
cursor.execute(select_sql)

# 打印表中共有多少记录
print('记录数为：', cursor.rowcount)

# 打印所有记录内容
print(f'内容为：{cursor.fetchall()}')

# 设置游标回零
cursor.rownumber = 0

# 打印第一条记录
print('第一条记录为：{}'.format(cursor.fetchone()))

cursor.close()

conn.close()
